You can implement a grow-zone function that the Memory Manager calls when it cannot fulfill a memory request. You should use the grow-zone function only as a last resort to free memory when all else fails. For explanations of how grow-zone functions work and an example of a memory-management scheme that uses a grow-zone function, see the discussion of low-memory conditions in the chapter "Introduction to Memory Management" in this book.
The SetGrowZone procedure specifies which function the Memory Manager should use for the current zone. The grow-zone function should call the GZSaveHnd function to receive a handle to a relocatable block that the grow-zone function must not move or purge.
To specify a grow-zone function for the current heap zone, pass a pointer to that function to the SetGrowZone procedure. Ordinarily, you call this procedure early in the execution of your application.
If you initialize your own heap zones besides the application and system zones, you can alternatively specify a grow-zone function as a parameter to the InitZone procedure.
PROCEDURE SetGrowZone (growZone: ProcPtr);
The SetGrowZone procedure sets the current heap zone's grow-zone function as designated by the growZone parameter. A NIL parameter value removes any grow-zone function the zone might previously have had.
The Memory Manager calls the grow-zone function only after exhausting all other avenues of satisfying a memory request, including compacting the zone, increasing its size (if it is the original application zone and is not yet at its maximum size), and purging blocks from it.
See "Grow-Zone Functions" for a complete description of a grow-zone function.
Your grow-zone function must call the GZSaveHnd function to obtain a handle to a protected relocatable block that the grow-zone function must not move, purge, or delete.
FUNCTION GZSaveHnd: Handle;
The GZSaveHnd function returns a handle to a relocatable block that the grow-zone function must not move, purge, or delete. It returns NIL if there is no such block. The returned handle is a handle to the block of memory being manipulated by the Memory Manager at the time that the grow-zone function is called.